import HttpUtil from '../utils/httpUtil.js'

export default {
    login(user, dialog,callback) {
        HttpUtil.post({
            uri: '/api/studentLogin', dialog:dialog,data: user, success: (data) => {
                HttpUtil.setToken(data.token);
                getApp().getToken();
                callback(data);
            }
        });
    },

    checkToken(token, callback) {
        HttpUtil.post({
            uri: '/api/checkToken', data: token, success: (data) => {
                callback(data);
            }
        });
    },

    modify(user, callback) {
        HttpUtil.post({
            uri: '/api/updateStudent',
            data: user,
            success: (data) => {
                callback(data);
            }
        });
    },

    updatePassword(user, callback) {
        HttpUtil.post({
            uri: '/api/updatePassword',
            data: {
                username:user.username,
                password:user.password,
            },
            success: (data) => {
                callback(data);
            }
        });
    },

    logout(callback) {
        HttpUtil.get({
            uri: '/api/logout',
            success: () => {
                callback('退出登录成功!');
            }
        });
    },

    register(username,password,callback){
        HttpUtil.post({
            uri: '/api/register',
            data: {
                username:username,
                password:password,
            },
            success: (data) => {
                callback(data);
            }
        });

    }
}